# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=daala
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgdesc="Daala is next-next-gen video compression technology from Xiph.org, Mozilla and others (mingw-w64)"
pkgver=r1505.52bbd43
pkgrel=1
arch=('any')
url="https://www.xiph.org/daala/"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-check"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "git")
depends=("${MINGW_PACKAGE_PREFIX}-libogg"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-SDL2")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
options=('strip' 'staticlibs')
source=("${_realname}"::"git+https://github.com/xiph/daala.git#commit=52bbd4365ab5febdbb73220c4e6ad9c9bf65231b"
        0001-make-daalabase-public.mingw.patch
        0002-make-daalabase-public.mingw.patch
        0003-missing-include.patch
        0004-xp-sp2.all.patch
        0005-no-pkg-config-prefix.mingw.patch)
sha256sums=('SKIP'
            '95d4e2b17390f98bd2de817a86d971a20c93c7209b028514306d6849af34d0fb'
            '85c9aaf491807adadc9c35d578ba9d6db088fab080ae8fcd9564c782b8f50c6b'
            'e0fa61c5a40ece233fab171ede7fc8936d8fe706a820b371e1376f58b09166a5'
            'b4fd487b6475ed108b31c363dd4cf078222dcfd01b04efec3fc7bc656847249a'
            '3272bae9d62b11ba71818f020f6f9968079cd43f07bd9425ba636b69c88ca743')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${srcdir}/${_realname}
  patch -p1 -i ${srcdir}/0001-make-daalabase-public.mingw.patch
  patch -p1 -i ${srcdir}/0002-make-daalabase-public.mingw.patch
  patch -p1 -i ${srcdir}/0003-missing-include.patch
  patch -p1 -i ${srcdir}/0004-xp-sp2.all.patch
  patch -p1 -i ${srcdir}/0005-no-pkg-config-prefix.mingw.patch

  autoreconf -fi
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-shared \
    --enable-static \
    --enable-tools \
    --disable-unit-tests

   make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  install -Dm644 ${srcdir}/${_realname}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
